package com.ttt.gdfood.mapper;

import com.ttt.gdfood.entity.Comment;
import com.ttt.gdfood.entity.Note;
import org.apache.ibatis.annotations.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Mapper
public interface CommentMapper {
    @Select("SELECT * FROM comment WHERE nid=#{nid} ORDER BY id DESC")
    @Results({
            @Result(property = "user",column = "uid",one=@One(select="com.ttt.gdfood.mapper.UserMapper.findById"))
    })
    List<Comment> allCommentByUid(int nid);

    // 添加评论
    @Insert("INSERT INTO comment(content,create_time,uid,nid) VALUES(#{content},#{create_time},#{uid},#{nid})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    @Transactional
    void addComment(Comment comment);
}
